#include "drogon/drogon.h"
#include "base/util/string_util.h"
#include "impl/HelloAppService.h"
#include "ServiceManager.h"

int main() {
    trantor::Logger::setLogLevel(trantor::Logger::kDebug);
    drogon::app().setThreadNum(std::thread::hardware_concurrency() * 2);
    // AOP
    drogon::app().registerBeginningAdvice([]() {
        LOG_INFO << "Event loop is running!";

        auto impl = new HelloAppServiceImpl();
        impl->init();
        emoney::ServiceManager::instance().add_service(impl);

    });

    drogon::app().registerNewConnectionAdvice([](const trantor::InetAddress & peer, const trantor::InetAddress & local) {
        LOG_INFO << "New connection: " << peer.toIpPort() << "-->" << local.toIpPort();
        return true;
    });

   

    uint16_t port = 0;
    char* pathvar = getenv("DPORT");
    if (pathvar != nullptr) {
        port = atoi(pathvar);
    } else {
        port = 7770;
    }

    drogon::app().addListener("0.0.0.0", port).run();
}
